﻿using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    public class inv_StorageService : inv_StorageIService
    {
        private readonly MyDbContext MyDbContext;
        public inv_StorageService(MyDbContext myDb)
        {
            this.MyDbContext = myDb;
        }
        public async Task<int> Add(inv_Storage inv_storage)
        {
            await MyDbContext.inv_Storage.AddAsync(inv_storage);
            return await MyDbContext.SaveChangesAsync();
        }

        public async Task<int> Delete(int ow_id)
        {
            var del = MyDbContext.inv_Storage.Find(ow_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        public async Task<List<bs_dict_data>> GetAttribute()
        {
            return await MyDbContext.bs_dict_data
       .Where(w => w.IsDeleted == false)
       .ToListAsync();
        }

        public async Task<List<bs_dict_image>> GetImage()
        {
            return await MyDbContext.bs_dict_image
                .Where(w => w.IsDeleted == false)
                .ToListAsync();
        }

        public async Task<List<bs_dict_image>> GetModel()
        {
            return await MyDbContext.bs_dict_image
                .Where(w => w.IsDeleted == false)
                .ToListAsync();
        }

        public async Task<List<bs_dict_data>> GetUnit()
        {
            return await MyDbContext.bs_dict_data
      .Where(w => w.IsDeleted == false)
      .ToListAsync();
        }

        public async Task<List<bs_Warehouse>> GetWarehouse()
        {
            return await MyDbContext.bs_Warehouse
               .Where(w => w.IsDeleted == false)
               .ToListAsync();
        }

        public async Task<List<inv_Storage>> Query()
        {
            return await MyDbContext.inv_Storage
       .Where(w => w.IsDeleted == false)
       .ToListAsync();
        }

        public async Task<int> Update(inv_Storage inv_storage)
        {
            MyDbContext.inv_Storage.Update(inv_storage);
            return await MyDbContext.SaveChangesAsync();
        }
    }
}
